#pragma once
#include <atlimage.h>
#include "AniObject.h"

namespace bs
{
	class Animation : public AniObject
	{
	public:
		Animation();
		virtual ~Animation();

		virtual void Start();
		virtual void Update(int elapsed, float speedFactor = 1.0f);
		virtual void Draw(HDC dc);

		bool LoadFile(const char* name, int r, int c, bool mirror = false);
		bool SetAniSeq(int start, int end, int loop = -1);            // when loop fall below 0, the anim stop; loopCount = -1 will not stop
		void ReverseAniSeq();      // swap the startFrame and the endFrame
		bool SetAlphaTrans(int duration, bool inc = true, bool isAnim = true);                            
		void SetInterval(int interval) { this->interval = interval; }
		bool ShowFrame(int frame);
		void SetStopOnEnd(bool stop) { this->stopOnEnd = stop; }

	private:
		void UpdateAlphaTrans();

 	private:
		bool showing;
		bool stopOnEnd;
	
		int startFrame;
		int endFrame;
		int curFrame;
		int loopCount;
		int interval;
		int timeCounter;

		bool alphaTrans;
		int alphaInc;
		int curAlpha;   // max : 255
		bool alphaAnim;

		CImage* image;
		int row;
		int col;
	};
}
